using Digitalmes.Application.Scada.Models;
using Digitalmes.Application.Scada.Services;

namespace Digitalmes.Application.Scada.Commands;

/// <summary>
/// 设备点检命令处理者。
/// </summary>
internal sealed class EquipmentInspectCommandHandler(IServiceScopeFactory serviceScopeFactory) : IRequestHandler<EquipmentInspectCommand, ScadaResult>
{
    public async Task<ScadaResult> Handle(EquipmentInspectCommand request, CancellationToken cancellationToken)
    {
        using var scope = serviceScopeFactory.CreateScope();
        var service = scope.ServiceProvider.GetRequiredService<IEquipmentInspectService>();
        EquipmentInspectInput input = new(request.LineCode, request.WsCode, request.Alias, request.PartNo, request.PassResult, request.DataList);
        var result = await service.InspectAsync(input, cancellationToken).ConfigureAwait(false);

        return result;
    }
}
